package demo_wty.servlet;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:wangtianyu(王天宇)
 * @Date：Created on 2020/3/27 0027 22:26
 * @Description:
 */
public class WtyJsonUtil {
    public static void writeJSON(HttpServletResponse resp,Object obj){
        resp.setCharacterEncoding("UTF-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
            writer.write(JSON.toJSONString(obj));
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            writer.flush();
            writer.close();
        }
    }
}
